<template>
  <div class="main-box">
    <!--开启页-->
    <div class="mocks-start-main">
      <p class="p1">试卷满分<span class="color-red">{{totalScore}}</span>分，限时<span class="color-red">{{parseInt(testTime / 60)}}</span>分钟</p>
      <p class="p2">请做好准备合理分配答题时间!</p>
      <button class="layui-btn layui-btn-mocks icon-lg" @click="hanleStartBtnClick">开始答题</button>
      <p class="p3">依照学术诚信条款，我保证此测试为本人独立完成</p>
    </div>
  </div>
</template>

<script>
  import { mapState, mapActions } from 'vuex';
  export default {
    name: "MocksStart",
    computed: {
      ...mapState([
        'totalScore',
        'testTime',
        'paperId',
        'courseId',
        'currentPart'
      ])
    },
    methods: {
      ...mapActions([
        'updateMocksStatus',
        'updateCurrentPart'
      ]),
      hanleStartBtnClick () {
        const _this = this;
        $.ajax({
          url: 'http://www.ruixinnj.com/test/save_test_time',
          // url: '/api/mocks/start',
          type: 'post',
          data: {
            paperId: _this.paperId,
            courseId: _this.courseId,
            random_string: (typeof random_string == 'string' ? random_string : ''),
            secret_string: (typeof secret_string == 'string' ? secret_string : '')
          },
          dataType: 'json',
          success: function (data) {
            if (data.status == 1){
              _this.updateMocksStatus('start');
              _this.updateCurrentPart(1);
              let _path = `/illustration/${_this.paperId}/${_this.courseId}/${_this.currentPart}`;
              _this.$router.push(_path);
            } else {
              layer.msg(data.msg);
            }
          }
        })
      }
    }
  }
</script>
